<?php
/**
 * Created by PhpStorm.
 * User: Celebration-Grey
 * Date: 2017/5/9
 * Time: 14:11
 */

namespace App\Http\Classes;


class Head extends Image
{
    private $dst180;
    private $dst50;
    private $dst30;
    private $url180;
    private $url50;
    private $url30;

    public function setDst()
    {
        // TODO: Implement setDst() method.
        $root = 'weiboimg/face/';
        $this -> dst180 = $root.'avatar_180/'.$this->name.$this->extension;
        $this -> dst50 = $root.'avatar_50/'.$this->name.$this->extension;
        $this -> dst30 = $root.'avatar_30/'.$this->name.$this->extension;
    }

    public function setUrl()
    {
        // TODO: Implement setUrl() method.
        $this -> url180 = $this -> host . $this -> dst180;
        $this -> url50 = $this -> host . $this -> dst50;
        $this -> url30 = $this -> host .$this -> dst30;
    }

    public function setOriginal()
    {
        // TODO: Implement setOriginal() method.
        $this -> original = 'weiboimg/face/original/';
    }

    public function getResult()
    {
        // TODO: Implement getResult() method.
        $data = [];
        $data['middle'] = $this -> url50;
        $data['big'] = $this -> url180;
        $data['small'] = $this -> url30;
        return $data;
    }

    public function howCrop($data, $src_img, $src_img_w, $src_img_h)
    {
        // TODO: Implement howCrop() method.
        $this -> croppedSize(180,180,$data,$this->dst180,$src_img,$src_img_w,$src_img_h);
        $this -> croppedSize(50,50,$data,$this->dst50,$src_img,$src_img_w,$src_img_h);
        $this -> croppedSize(30,30,$data,$this->dst30,$src_img,$src_img_w,$src_img_h);
    }

    public function updateUser()
    {
        // TODO: Implement updateUser() method.
        $this -> setUrl();
        $user = new User($_COOKIE['user_id']);
        $user = $user->updateHead($this->url50,$this->url180,$this->url30);
        if($user){
            $this -> code = 200;
            $this -> msg = 'Head image saved and update success!';
        }
        else{
            $this -> code = 304;
            $this -> msg = 'Head image saved but update error!';
        }
    }
}